$(function () {

    getdiz()

    function getdiz() {
        $.ajax({

            url: "/api/address/list",
            method: "GET",

            success: (res) => {
                // console.log(res);
                var htmlStr = template('tpl-table', res)
                $('.address-list').html(htmlStr)

                for (i = 0; i < $('.default').length; i++) {

                    // console.log($('.default')[i].innerHTML);
                    if ($('.default')[i].innerHTML == 1) {
                        $('.default')[i].style.display = ' block'
                        $('.default')[i].innerHTML = '默认'
                    }
                }
            },
        });
    }


    // $('.address-list').on('click', '.l', function (e) {
    //     e.preventDefault()
    //     location.href = './addressAdd.html'
    // })

    $('.address-list').on('click', '.c', function (e) {
        e.preventDefault()
        var id = $(this).attr('data-id')
        var city_id = $(this).attr('data-shi')
        var district_id = $(this).attr('data-xian')
        var province_id = $(this).attr('data-sheng')
        localStorage.setItem('id', id)
        localStorage.setItem('city_id', city_id)
        localStorage.setItem('district_id', district_id)
        localStorage.setItem('province_id', province_id)

        location.href = './addressAdd - 副本.html'
    })



    $('.address-list').on('click', '.r', function (e) {
        e.preventDefault()
        // console.log("ok");
        var id = $(this).attr('data-id')
        console.log(id);

        $.ajax({
            url: "/api/address/delete",
            method: "POST",

            data: {
                id: id
            },
            body: {
                id: id
            },
            success: function (res) {
                console.log(res);
            }
        });

        getdiz()
    })







})